ATM Central Server - interface layer
In this example the ATM Central Server (atmcs) interacts with the
ATM clients and relays transaction requests to individual banks.
The interface design follows the object factory pattern . This example
demonstrates how to:
-
Design interfaces using the object factory pattern
-
Use an interface as a servant class
-
Implement interfaces as both server and client
-
Manage CORBA objects with a hash table
This server must be used together with the Bank
Server. Since this implementation has only interface layer objects
and no persistent objects, some bank and account information is hard coded
in the login method of SessionMgrImpl.
Source Files
-
atmcs.idl
IDL file for the interfaces SessionIF and SessionMgrIF in the atmcs
module. (IF stands for interface.) Also defined are exception
"AtmcsError", a cash card data structure CardInfo, and an account information
structure AccountInfo.
SessionMgrIF only has login and logout operations
exposed, though the implementation class may have conventional object management
operations.
-
Server.java
The Server code, which has a main function that creates an instance
of the SessionMgrImpl class and calls obj_is_ready()and
impl_is_ready() to make it available to the client.
The code contains the following interface implementation classes:
-
SessionMgrImpl
Implementation for the session manager interface "SessionMgrIF". It
implements access control methods: login and logout.
Mangement methods like remove (removes a session), and showSessions
are implemented but not exposed as interface operations.
-
SessionImpl
Implementation for the interface "SessionIF". It implements
get methods: getBalance, getAccountInfo, getAccountHistory, and
transaction methods: deposit, withdraw, transferTo, payBill.
Each session is created with an AccountIF object as one of the input
argument. AccountIF thus serves as a servant object. All interface
methods invoke the corresponding methods on this servant object.
Since this implementation has no persistent objects, some bank and account
information is hard coded in the login method.
-
Client.java
The client code. It binds to the SessionMgrImpl object
using a server name (e.g. "ATM Session Manager"). It then waits for
user commands to open accounts and to initiate transactions. The
runTerminal method translates command line inputs into method calls to
the server. One may also run the client with an input text file that
contains multiple command lines. An example is in Test1.txt.
Batch Files
-
build.bat
A batch file for building the client and server on Windows.
It will first invoke the IDL compiler and then compile the server and client
source codes. A subdirectory named "atmcs" will be created, which
contains the CORBA stub and skeleton codes and their corresponding class
files.
-
runsrv.bat
A batch file for running the server.
-
client.bat
A batch file for running the client. The command line format
is:
client [hostname] [command.txt]
where the optional hostname (or IP address) is where the server is running
and command.txt is an optional input command file such as Test1.txt.
Running the Codes
This example was developed under VisiBroker (link).
To run the codes, make sure that the VisiBroker Smart Agent (osagent) is
running on the server object's network. Then enter the commands:
On Windows:
start runsrv
client (or client [hostname] [Test1.txt])
On Unix:
vbj Server &
vbj Client (or vbj Client [hostname] [Test1.txt])